const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    // LIFE-CYCLE CALLBACKS:

    private _material: cc.MaterialVariant;
    private posx = 0;
    private posy = 0;

    onLoad() {
        if (this.node.getComponent(cc.Label)) {
            this._material = this.node.getComponent(cc.Label).getMaterial(0);
        } else if (this.node.getComponent(cc.Sprite)) {
            this._material = this.node.getComponent(cc.Sprite).getMaterial(0);
        }
        this.node.on(cc.Node.EventType.TOUCH_MOVE, (event: cc.Event.EventTouch) => {
            // this.posx = event.getLocationX();
            // this.posy = event.getLocationY();
            this.posx += event.getDeltaX() * 0.05;
            this.posy += event.getDeltaY() * 0.05;
            this._material.setProperty('posx', this.posx);
            this._material.setProperty('posy', this.posy);
        });
    }

    start() {}
    // update (dt) {}
}
